﻿using Core.DataAccess.Tools.Implementations;
using Core.DataAccess.Tools.Interfaces;
using Microsoft.Practices.Unity;
using Unity.AutoRegistration;
using Core.DataAccess.Interfaces;
using Core.DataAccess.Implementations;
namespace Core.Relations
{
    //set up relations between interfaces and implementations
    internal class DependencyResolver
    {
        private IUnityContainer container;

        //Get a container with registered types and interfaces
        public Microsoft.Practices.Unity.IUnityContainer GetRegisteredTypes()
        {
            if (container == null)
                RegisterTypes();
            return container;
        }

        private void RegisterTypes()
        {

            container = new UnityContainer();

            #region register NHibernate helper classes which work with sessions
            container.RegisterType<ISessionFactoryManager, SessionFactoryManager>();
            container.RegisterType<IConversation, Conversation>();
            container.RegisterType(typeof(IRepository<>),typeof(Repository<>));
            #endregion

            #region register DataProvider Types

            container.RegisterType<IUserDataProvider, UserDataProvider>();
            container.RegisterType<ITagDataProvider, TagDataProvider>();
            container.RegisterType<IQuestionListDataProvider, QuestionListDataProvider>();
            container.RegisterType<IQuestionDataProvider, QuestionDataProvider>();
            container.RegisterType<IAnswerDataProvider, AnswerDataProvider>();

            #endregion
        }
    }
}
